package com.itguigu.spzx.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

/**
 * @author lxr
 * @date 2025/10/21 16:06
 * 全局网关过滤器
 */
@Component
public class MyFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        ServerHttpRequest request = exchange.getRequest();
        String userId = "123";
        request.mutate().header("userId",userId);
        exchange.mutate().request(request);

        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return -1;
    }
}
